package com.ly.chatsimple.ui.chat.viewmodel

import androidx.compose.runtime.mutableStateListOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ly.chatsimple.ui.chat.usecase.GetClientInfoUseCase
import com.ly.data.FuncProto.Client
import com.ly.nethub.utils.LogUtils
import kotlinx.coroutines.launch

class MainViewModel(
    private val getClientInfoUseCase: GetClientInfoUseCase = GetClientInfoUseCase()
) : ViewModel() {

    val clients = mutableStateListOf<Client>()

    fun refresh() {
        viewModelScope.launch {
            val result = getClientInfoUseCase()
            LogUtils.d("$TAG 获取客户端结果:${result.data?.clientsList}")
            clients.clear()
            clients.addAll(result.data?.clientsList ?: emptyList())
        }
    }

    companion object {
        const val TAG = "MainViewModel"
    }
}
